package com.higold.cloud.mvp.presenter

import com.higold.cloud.base.BasePresenter
import com.higold.cloud.mvp.contract.AchieveContract
import com.higold.cloud.mvp.model.AchieveModel
import com.higold.cloud.net.exception.ExceptionHandle

/**
 *    author : lxz
 *    date   : 2019/8/28 10:22
 *    desc   :
 */
class AchievePresenter : BasePresenter<AchieveContract.View>(), AchieveContract.Presenter{

    private val achieveModel by lazy { AchieveModel() }

    override fun getAchieveInfo(type : Int) {
        checkViewAttached()
        mRootView?.showLoading()
        val disposable = achieveModel.requestAchieveList(type)
                .subscribe({ achieve ->
                    mRootView?.setAchieveInfo(achieve)
                }, { throwable ->
                    //处理异常
                    mRootView?.showError(ExceptionHandle.handleException(throwable), ExceptionHandle.errorCode)
                })
        addSubscription(disposable)
    }

}